#ifndef V4L2API_H
#define V4L2API_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <linux/videodev2.h>
#include <sys/ioctl.h>
#include <string.h>
#include <sys/mman.h>

class V4l2Api
{
public:
    V4l2Api(const char*devname);
    ~V4l2Api();
    int getSize() const;//获取一帧数据占用的空间
    void getFrame(unsigned char* yuv, int size);
    void start();
    void stop();
    void initVideo(int w=640, int h=480, int fmt=V4L2_PIX_FMT_YUYV, int count=4);
    void yuv422ToRgb(unsigned char *yuv, int w, int h, unsigned char *rgb);
private:
    void setImageFormat(int w, int h, int fmt);
    int fd;
    int cout;//缓冲区个数
    unsigned char **mptr;//存储缓冲区映射后的首地址
    unsigned int  *mptrsize; //存储每个缓冲区大小
    int width;//像素宽
    int height;//像素高
    unsigned int format;//存储采集像素格式
    unsigned int size;
    bool status;
};

#endif // V4L2API_H
